﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web;

namespace AviagePortal.Layouts.AviagePortal
{
    /// <summary>
    /// /_layouts/15/AviagePortal/SearchWithType.ashx?searchText=av&language=English&deviceType=PC&searchType=Media
    /// /_layouts/15/AviagePortal/SearchWithType.ashx?searchText=av&language=English&deviceType=PC&searchType=AboutUs
    /// /_layouts/15/AviagePortal/SearchWithType.ashx?searchText=av&language=English&deviceType=PC&searchType=Career
    /// /_layouts/15/AviagePortal/SearchWithType.ashx?searchText=av&language=English&deviceType=PC&searchType=Service
    /// /_layouts/15/AviagePortal/SearchWithType.ashx?searchText=av&language=English&deviceType=PC&searchType=Service
    /// </summary>
    public partial class SearchWithType : IHttpHandler
    {
       public bool IsReusable
        {
            get { return true; }
        }

       public void ProcessRequest(HttpContext context)
       {
           System.Web.Script.Serialization.JavaScriptSerializer jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
           context.Response.ContentType = "application/json";
           string searchText = context.Request.QueryString["searchText"];
           string language = context.Request.QueryString["language"];
           string deviceType = context.Request.QueryString["deviceType"];
           string searchType = context.Request.QueryString["searchType"];
           SearchResultSummary result = SearchOperation.Search(searchText, searchType, language, deviceType);
           context.Response.Write(jsonSerializer.Serialize(result));
       }
    }
}
